define(['map'], function(map) {
    'use strict';
    
    function Bar(matadata) {
        this.matadata = matadata;
        this.echartslayer = new ol3Echarts(null, {
            hideOnMoving: true,
            hideOnZooming: true
        });
        this.echartslayer.appendTo(map.getMap());
    }

    Bar.prototype.setMateData = function (matadata) {
        this.matadata = matadata;
    }

    Bar.prototype.init = function () {
        this.options = {
            color: ['#3398DB'],
            tooltip : {
              trigger: 'axis',
              axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
              }
            },
            legend: {
              orient: 'vertical',
              x: "right",
              show: true,
              data: [],
              selectedMode: 'multiple',
              textStyle: {
                color: '#fff',
                fontSize: 14
              },
            },
            grid: [],
            xAxis : [],
            yAxis : [],
            series: []
        };
        this.options["legend"]["data"] = this.matadata["legend_data"];
        this.matadata["series_zqInfo_data"].forEach((item, index) => {
            this.options.grid.push({
                show: true,
                containLabel: false,
                borderWidth: 0,
                borderColor: '#fff',
                width: item["size"][0],
                height: item["size"][1]
            });
            this.options.xAxis.push({
                type : 'category',
                show: true,
                gridIndex: index,
                nameTextStyle: {
                    color: '#3c3c3c'
                },
                axisLine: {
                    show: false,
                    onZero: false
                },
                axisLabel: {
                    show: false,
                    interval: 0,
                    rotate: -45,
                    textStyle: {
                        color: '#3c3c3c',
                        fontSize: 10
                    }
                },
                axisTick: {
                    show: false
                },
                data : item["xaxis_data"]
            });
            this.options.yAxis.push({
                type: 'value',
                show: true,
                min: 0.001,
                splitLine: {show: false},
                axisLabel: {
                    show: false
                },
                axisLine: {
                    show: false,
                    onZero: false
                },
                nameGap: '1',
                axisTick: {
                    show: false
                },
                nameTextStyle: {
                    color: '#3c3c3c',
                    fontSize: 14
                },
                gridIndex: index
            });
            this.options.series.push({
                name: item["yaxis_data_name"],
                type: 'bar',
                barWidth: '15',
                coordinates: item["coordinate"],
                data: item["data"],
                xAxisIndex: index,
                yAxisIndex: index
            })
        })
        this.echartslayer.setChartOptions(this.options);
    }

    Bar.prototype.setVisible = function (bool) {
        this.echartslayer.setVisible(bool);
    }

    Bar.prototype.destory = function () {
        this.echartslayer.remove();
    }
    return Bar
});